package com.homedo.distributed.id.client.gen.command;

import com.homedo.common.util.http.HttpCommandFactory;
import com.homedo.distributed.id.client.gen.buffer.GenBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class GenCommandFactory {
    private static final Logger _LOGGER = LoggerFactory.getLogger(HttpCommandFactory.class);

    public static final String COMMAND_GROUP_PREFIX = "gen_";
    public static final String COMMAND_GROUP_SUFFIX = "_group";

    public static final String COMMAND_NAME_PREFIX = "gen_";

    public static <R> GenCommand<R> create(String bizTag, int genType, GenBuffer<R> genBuffer) {
        String commandGroup = bizTag;
        if (!commandGroup.startsWith(COMMAND_GROUP_PREFIX)) {
            commandGroup = COMMAND_GROUP_PREFIX + commandGroup;
        }

        if (!commandGroup.endsWith(COMMAND_GROUP_SUFFIX)) {
            commandGroup = commandGroup + COMMAND_GROUP_SUFFIX;
        }

        String commandName = bizTag + "#" + genType;
        if (!commandName.startsWith(COMMAND_NAME_PREFIX)) {
            commandName = COMMAND_NAME_PREFIX + commandName;
        }

        GenCommand genCommand = new GenCommand<>(commandGroup, commandName);
        genCommand.setGenBuffer(genBuffer);

        return genCommand;
    }

}
